package com.j2eefast.flowable.bpm.service;


import com.j2eefast.flowable.bpm.entity.ClueEntity;
import com.j2eefast.flowable.bpm.mapper.ClueMapper;
import com.j2eefast.common.core.mutidatasource.annotaion.DataSource;
import com.j2eefast.common.core.page.Query;
import com.j2eefast.common.core.utils.PageUtil;
import com.j2eefast.common.core.utils.ToolUtil;
import com.j2eefast.framework.utils.Constant;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import javax.annotation.Resource;
import org.springframework.transaction.annotation.Transactional;
import java.util.Map;
import java.util.Arrays;
/**
 *
 * 线索池Service接口
 * @author: yhli
 * @date 2020-06-30 16:41
 */
@Service
public class ClueService extends ServiceImpl<ClueMapper,ClueEntity> {

	@Resource
	private ClueMapper clueMapper;

	/**
	 * mybaitis-plus 页面分页查询
     */
    @DataSource(name="APP")
	public PageUtil findPage(Map<String, Object> params) {
        QueryWrapper<ClueEntity> queryWrapper = new QueryWrapper<ClueEntity>();
           String ShortHand = (String) params.get("ShortHand");
         queryWrapper.eq(ToolUtil.isNotEmpty(ShortHand), "ShortHand", ShortHand);
          String Source = (String) params.get("Source");
         queryWrapper.eq(ToolUtil.isNotEmpty(Source), "Source", Source);
          String CustomerName = (String) params.get("CustomerName");
        queryWrapper.like(ToolUtil.isNotEmpty(CustomerName), "CustomerName", CustomerName);
          String CustomerAddress = (String) params.get("CustomerAddress");
         queryWrapper.eq(ToolUtil.isNotEmpty(CustomerAddress), "CustomerAddress", CustomerAddress);
          String ContactInfo = (String) params.get("ContactInfo");
         queryWrapper.eq(ToolUtil.isNotEmpty(ContactInfo), "ContactInfo", ContactInfo);
          String Industry = (String) params.get("Industry");
         queryWrapper.eq(ToolUtil.isNotEmpty(Industry), "Industry", Industry);
          String IntentionCar = (String) params.get("IntentionCar");
         queryWrapper.eq(ToolUtil.isNotEmpty(IntentionCar), "IntentionCar", IntentionCar);
          String Needs = (String) params.get("Needs");
         queryWrapper.eq(ToolUtil.isNotEmpty(Needs), "Needs", Needs);
          String Budget = (String) params.get("Budget");
         queryWrapper.eq(ToolUtil.isNotEmpty(Budget), "Budget", Budget);
          String IsHoldCash = (String) params.get("IsHoldCash");
         queryWrapper.eq(ToolUtil.isNotEmpty(IsHoldCash), "IsHoldCash", IsHoldCash);
          String ExitsCar = (String) params.get("ExitsCar");
         queryWrapper.eq(ToolUtil.isNotEmpty(ExitsCar), "ExitsCar", ExitsCar);
          String PlanTime = (String) params.get("PlanTime");
         queryWrapper.eq(ToolUtil.isNotEmpty(PlanTime), "PlanTime", PlanTime);
          String CStatus = (String) params.get("CStatus");
         queryWrapper.eq(ToolUtil.isNotEmpty(CStatus), "CStatus", CStatus);
          String Royalty = (String) params.get("Royalty");
         queryWrapper.eq(ToolUtil.isNotEmpty(Royalty), "Royalty", Royalty);
          String OAId = (String) params.get("OAId");
         queryWrapper.eq(ToolUtil.isNotEmpty(OAId), "OAId", OAId);
          String Level = (String) params.get("Level");
         queryWrapper.eq(ToolUtil.isNotEmpty(Level), "Level", Level);
          String CuStyles = (String) params.get("CuStyles");
         queryWrapper.eq(ToolUtil.isNotEmpty(CuStyles), "CuStyles", CuStyles);
          String CreateTime = (String) params.get("CreateTime");
         queryWrapper.eq(ToolUtil.isNotEmpty(CreateTime), "CreateTime", CreateTime);
          String CreateId = (String) params.get("CreateId");
         queryWrapper.eq(ToolUtil.isNotEmpty(CreateId), "CreateId", CreateId);
          String UpdateTime = (String) params.get("UpdateTime");
         queryWrapper.eq(ToolUtil.isNotEmpty(UpdateTime), "UpdateTime", UpdateTime);
          String UpdateId = (String) params.get("UpdateId");
         queryWrapper.eq(ToolUtil.isNotEmpty(UpdateId), "UpdateId", UpdateId);
          String FCode = (String) params.get("FCode");
         queryWrapper.eq(ToolUtil.isNotEmpty(FCode), "FCode", FCode);
          String UserId = (String) params.get("UserId");
         queryWrapper.eq(ToolUtil.isNotEmpty(UserId), "UserId", UserId);
          String Remarks = (String) params.get("Remarks");
         queryWrapper.eq(ToolUtil.isNotEmpty(Remarks), "Remarks", Remarks);
          String Trusts = (String) params.get("Trusts");
         queryWrapper.eq(ToolUtil.isNotEmpty(Trusts), "Trusts", Trusts);
  		Page<ClueEntity> page = clueMapper.selectPage(new Query<ClueEntity>(params).getPage(), queryWrapper);
		return new PageUtil(page);
    }

    /**
     * 自定义分页查询，含关联实体对像
     */
    @DataSource(name="APP")
	public PageUtil findPage(Map<String, Object> params,ClueEntity clueEntity) {
		Page<ClueEntity> page = clueMapper.findPage(new Query<ClueEntity>(params).getPage(), clueEntity,(String) params.get(Constant.SQL_FILTER))  ;
		return new PageUtil(page);
	}
	/**
     * 批量删除
     */
    @DataSource(name="APP")
	@Transactional(rollbackFor = Exception.class)
	public boolean deleteClueByIds(Long[] ids) {
		return removeByIds(Arrays.asList(ids));
	}

	/**
     * 单个删除
     */
    @DataSource(name="APP")
	public boolean deleteClueById(Long Id) {
		return removeById(Id);
	}

	/**
     * 保存
     */
    @DataSource(name="APP")
	public boolean saveClue(ClueEntity clue){
        return save(clue);
    }

	/**
     * 修改根居ID
     */
    @DataSource(name="APP")
	public boolean updateClueById(ClueEntity clue) {
		return updateById(clue);
	}

	/**
     * 根居ID获取对象
     */
    @DataSource(name="APP")
	public ClueEntity getClueById(Long Id){
		return getById(Id);
	}
}
